package com.heo.protocol.packet;

import org.apache.log4j.Logger;

import com.heo.util.ByteHelper;

public class GetDeviceCodeResp extends BasePacket
{
  private int BODY_LENGTH = -1;// 包体长未知

  private static final String PACKET_NAME = "[获取设备二维码应答包]";
  private static Logger log = Logger.getLogger(GetDeviceCodeResp.class);

  private byte result = 0x02;// 默认返回错误
  private String deviceCode = null;

  public GetDeviceCodeResp(short sequenceId) throws Exception
  {
    super(PACKET_NAME);
    super.totalLength = (short) (HEAD_LENGTH + BODY_LENGTH);
    super.commandId = DeviceCommand.GET_DEVICE_CODE_RESP;
    super.sequenceId = sequenceId;
  }

  @Override
  public int getTotalLength()
  {
    if (deviceCode == null)
    {
      return super.HEAD_LENGTH + 1;
    }
    else
    {
      return super.HEAD_LENGTH + 1 + deviceCode.length();
    }
  }

  @Override
  public byte[] getPacketBody()
  {
    if (deviceCode == null)
    {
      return ByteHelper.margeByte(new byte[] { result }, null, null, null, null, null, null, null, null, null);
    }
    else
    {
      return ByteHelper.margeByte(new byte[] { result }, deviceCode.getBytes(), null, null, null, null, null, null, null, null);
    }
  }

  public static void main(String[] args)
  {

  }

  @Override
  public void makeBody()
  {

  }

  public byte getResult()
  {
    return result;
  }

  public void setResult(byte result)
  {
    this.result = result;
  }

  public String getDeviceCode()
  {
    return deviceCode;
  }

  public void setDeviceCode(String deviceCode)
  {
    this.deviceCode = deviceCode;
  }

}
